package com.stedu.controller;

import com.stedu.bean.GamingPlatform;
import com.stedu.bean.RespBean;
import com.stedu.exception.SteduException;
import com.stedu.service.AdminService;
import com.stedu.service.GamingPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/admin/GamingPlatformController")
public class GamingPlatformController  {
    @Autowired
    private GamingPlatformService gamingPlatformService;
    @Autowired
    private AdminService adminService;


        @PostMapping
        public RespBean addGamingPlatform(@RequestBody GamingPlatform gamingPlatform) throws SteduException {


        //添加
            gamingPlatformService.add(gamingPlatform);
            return RespBean.ok("添加成功");


    }
    @PutMapping
    public RespBean upGamingPlatform(@RequestBody GamingPlatform gamingPlatform) throws SteduException {
        System.out.println("----------");

            gamingPlatformService.update(gamingPlatform);
            return RespBean.ok("修改成功");
    }
    @DeleteMapping("/{plaid}")
    public RespBean delGamingPlatform(@PathVariable("plaid") Integer plaid) throws SteduException {

            gamingPlatformService.del(plaid);
            return RespBean.ok("删除成功");


    }
    @GetMapping("/findAll")
    public RespBean findAll()  {

            List<GamingPlatform> selectall = gamingPlatformService.selectall();

            return RespBean.ok("", selectall);





    }
    @GetMapping("/{plaid}")
    public RespBean findById(@PathVariable("plaid") Integer plaid)  {

            GamingPlatform gamingPlatform = gamingPlatformService.selectById(plaid);
            return RespBean.ok("", gamingPlatform);


    }
    @GetMapping("/findPlaAndGames")
    public RespBean findPlaAndGames(){


            List<Map<String, Object>> plaAndGames = adminService.findPlaAndGames();
            return RespBean.ok("",plaAndGames);



        }

    }

